package com.endbd.purchase.purchase_order.control;

import com.endbd.feignapi.model.purchase.CPurchase;
import com.endbd.feignapi.util.PageModel;
import com.endbd.feignapi.util.ResultMessage;
import com.endbd.purchase.purchase_order.model.PurchaseOrderCondition;
import com.endbd.purchase.purchase_order.service.PDMLService;
import com.endbd.purchase.purchase_order.service.PQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/purchase")
public class PurchaseApi {
    @Autowired
    private PQueryService queryService;  //采购单的查询接口自动装配

    @Autowired
    private com.endbd.purchase.purchase_order.service.PDMLService PDMLService;    //采购单的增、删、改的接口自动装配

    @RequestMapping("/view2")
    public ResultMessage queryPageByCondition(@RequestParam Integer checkStatus, @RequestParam Integer  rkStatus) {
        PurchaseOrderCondition condition = new PurchaseOrderCondition();
        condition.setCheckStatus(checkStatus);
        condition.setRkStatus(rkStatus);

        PageModel<CPurchase> pageModel = new PageModel<>();
        pageModel.setPageSize(999);

        PageModel<CPurchase> cPurchasePageModel = queryService.queryPurchasePageByCondition(condition, pageModel);

        ResultMessage message = new ResultMessage();
        message.setStatus("200");
        message.setFlag(true);
        message.setMsg("条件查询--查到了！");
        message.setResultData(cPurchasePageModel);
        return message;
    }

    @RequestMapping("/updateView")
    public ResultMessage updateWarehouseIdAndRkStatus(@RequestParam String p,@RequestParam String w){
        PurchaseOrderCondition poc = new PurchaseOrderCondition();
        poc.setPurchaseId(p);
        poc.setWarehouseId(Integer.parseInt(w));
        int i = PDMLService.updateWarehouseIdAndRkStatus(poc);
        ResultMessage message = new ResultMessage();
        if (i == 0 ) {
            message.setStatus("202");
            message.setFlag(false);
            message.setMsg("修改仓库id、入库状态失败！！");
            return message;
        }
        message.setStatus("200");
        message.setFlag(true);
        message.setMsg("修改仓库id、入库状态成功！！");

        return message;
    }
}
